<?php

namespace app\index\controller;

use think\Db;
use think\Request;

class Record
{
    // 入口
    public function index()
    {
        return ['data' => '欢迎来到api.vchao.top', 'code' => 1, 'message' => '操作完成'];
    }

    // 获取记录列表
    public function list()
    {
        $request = Request::instance();
        $number = $request->param('num');
        if (!$number) {
            $number = 10;
        }
        $res = Db::table('record')
            ->limit($number)
            ->select();
        return ['code' => 1, 'message' => 'successful', 'data' => $res];
    }

    // 新增记录
    public function insert()
    {
        $request = Request::instance();
        $record_eliminate = $request->param('eliminate');
        $record_disposal = $request->param('disposal');
        $record_time = $request->param('time');

        $data = ['record_disposal' => $record_disposal, 'record_eliminate' => $record_eliminate, 'record_time' => $record_time];
        $res = Db::table('record')->insert($data);

        if ($res) {
            return ['code' => 1, 'message' => 'success'];
        } else {
            return ['code' => 2, 'message' => 'fail'];
        }
    }
}
